//
//  GoOutHotTableView.m
//  ArtOfLiving
//
//  Created by 刘虎 on 16/5/1.
//  Copyright © 2016年 刘虎. All rights reserved.
//

#import "GoOutHotTableView.h"
#import "GoOutMainHeadView.h"
#import "HotTableViewCell.h"
#import "travelNotesModel.h"
#import "GoOutSpecialTopicDetialViewController.h"

@interface GoOutHotTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation GoOutHotTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    
    self = [super initWithFrame:frame style:style];
    if (self) {
        
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.delegate = self;
        self.dataSource = self;
        [self registerNib:[UINib nibWithNibName:@"HotTableViewCell" bundle:nil] forCellReuseIdentifier:@"travelNotesCELL"];
    }
    return self;
}

#pragma mark - -----tableView的代理方法---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.travelNotesDataSourceMArr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BaseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"travelNotesCELL" forIndexPath:indexPath];
    id model = self.travelNotesDataSourceMArr[indexPath.row];
    [cell setCellWithModel:model];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 120.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TravelNotesModel *model = self.travelNotesDataSourceMArr[indexPath.row];
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    GoOutSpecialTopicDetialViewController *goOutSpecialTopicDetialVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"GoOutSpecialTopicDetialViewController"];
    goOutSpecialTopicDetialVC.htmlUrl = model.view_url;
    goOutSpecialTopicDetialVC.navcTitle = model.title;
    [self.navC pushViewController:goOutSpecialTopicDetialVC animated:YES];
}

#pragma mark - -----为tableView创建头饰图----
- (void)creatTableHeadView {
    
    if (self.headViewDataSourceMArr.count == 0) {
        
        return;
    }
    UINib *nib = [UINib nibWithNibName:@"GoOutMainHeadView" bundle:nil];
    GoOutMainHeadView *headView = [[nib instantiateWithOwner:nil options:nil] firstObject];
    headView.frame = CGRectMake(0, 0, kScreenWidth, 300);
    headView.headViewModel = self.headViewDataSourceMArr;
    headView.naVC = self.navC;
    self.tableHeaderView = headView;
}


#pragma mark - 属性懒加载
- (NSMutableArray *)travelNotesDataSourceMArr {
    
    if (!_travelNotesDataSourceMArr) {
        
        _travelNotesDataSourceMArr = [[NSMutableArray alloc] init];
    }
    return _travelNotesDataSourceMArr;
}

- (NSMutableArray *)headViewDataSourceMArr {
    
    if (!_headViewDataSourceMArr) {
        
        _headViewDataSourceMArr = [[NSMutableArray alloc] init];
    }
    return _headViewDataSourceMArr;
}


@end
